package entities;

import java.io.Serializable;

/**
 * Objecto que representa um alcance de dados de uma
 * base de dados
 * 
 * @author Leonardo Lino Nº45340
 * @author Diogo Pires Nº40351
 */
public class Range implements Serializable{

	private final int MAX_THEATHERS;
	private int responsable;
	private int min;
	private int max;
	private int size;
	
	public Range(int min, int max, int responsable, int maxNrTheaters){
		this.min = min;
		this.max = max;
		this.responsable = responsable;
		this.MAX_THEATHERS = maxNrTheaters;
		
		if(max > min)
			size = max - min + 1;
		else{
			size = (MAX_THEATHERS - min + 1) + max;
		}
	}
	
	public Range(String rangeData){
		String[] parts = rangeData.split(":");
		
		this.MAX_THEATHERS = Integer.parseInt(parts[1]);
		this.responsable = Integer.parseInt(parts[2]);
		this.min = Integer.parseInt(parts[3]);
		this.max = Integer.parseInt(parts[4]);
		this.size = Integer.parseInt(parts[5]);
	}

	public int getMin() {
		return min;
	}

	public void setMin(int min) {
		this.min = min;
	}

	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getResponsable() {
		return responsable;
	}

	public void setResponsable(int responsable) {
		this.responsable = responsable;
	}
	
	public int getMaxTheaters() {
		return MAX_THEATHERS;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("RANGE");
		sb.append(':');
		sb.append(MAX_THEATHERS);
		sb.append(':');
		sb.append(responsable);
		sb.append(':');
		sb.append(min);
		sb.append(':');
		sb.append(max);
		sb.append(':');
		sb.append(size);
		
		return sb.toString();
	}
	
	
	
}
